import 'package:enterprise_v6_app/app/components/custom_app_bar.dart';
import 'package:enterprise_v6_app/app/components/toast_widget.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/modules/application/special_operation/special_list/job_plan_request/job_plan_request_controller.dart';
import 'package:enterprise_v6_app/app/modules/application/special_operation/special_list/job_plan_request/plan_risk_identification/plan_risk_identification_view.dart';
import 'package:enterprise_v6_app/app/modules/application/special_operation/special_list/job_plan_request/planning_request/planning_request_view.dart';

/// 作业计划申请
class JobPlanRequestWidget extends StatelessWidget {
  JobPlanRequestWidget({super.key});

  final controller = Get.put(JobPlanRequestController());

  @override
  Widget build(BuildContext context) {
    return GetBuilder(
        init: controller,
        builder: (_) {
          // 如果是查看详情修改,等待接口完成后再加载页面
          if (!controller.isApply &&
              controller.jobPlanDetailsEntity.id!.isEmpty) {
            return Scaffold(
              appBar: CustomAppBar(
                titleText: '作业计划申请',
              ),
            );
          }
          return Scaffold(
            appBar: CustomAppBar(
              titleText: '作业计划申请',
            ),
            body: DefaultTabController(
              length: 2,
              child: Column(
                children: [
                  Container(
                    margin: EdgeInsets.symmetric(horizontal: 50.w),
                    height: 54.w,
                    child: TabBar(
                      controller: controller.tabController,
                      onTap: (index) {
                        if (controller.isApply && index == 1) {
                          controller.tabController.animateTo(0);
                          AppToast.showWarning('请先申请计划');
                          return;
                        }
                        if (!controller.isIdentityUser && index == 1) {
                          controller.tabController.animateTo(0);
                          AppToast.showWarning('当前账号无辨识权限');
                        }
                      },
                      enableFeedback: false,
                      tabs: const [
                        Tab(text: '计划申请'),
                        Tab(text: '风险辨识'),
                      ],
                      dividerColor: Colors.transparent,
                      labelPadding: EdgeInsets.only(bottom: 20.w),
                      labelStyle: TextStyle(
                        fontSize: 16.sp,
                        fontWeight: FontWeight.w500,
                      ),
                      unselectedLabelStyle: TextStyle(
                        fontSize: 16.sp,
                        fontWeight: FontWeight.w500,
                      ),
                      labelColor: Colors.black,
                      unselectedLabelColor: const Color(0xffA0A7B5),
                      indicatorPadding:
                          EdgeInsets.only(top: 35.w, bottom: 10.w),
                      indicator: const BoxDecoration(
                        image: DecorationImage(
                          image: AssetImage(
                            AppImages.icon_app_work_plan,
                          ),
                        ),
                      ),
                    ),
                  ),
                  Expanded(
                    child: Container(
                      color: const Color(0xffF5F5F6),
                      child: TabBarView(
                        controller: controller.tabController,
                        physics:
                            !controller.isApply && controller.isIdentityUser
                                ? null
                                : const NeverScrollableScrollPhysics(),
                        children: [
                          PlanningRequestWidget(),
                          PlanRiskIdentificationWidget(),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
          );
        });
  }
}
